<%@page import="com.etc.zzsys.service.UserService"%>
<%@page import="com.etc.zzsys.service.impl.UserServiceImpl"%>
<%@page import="com.etc.zzsys.entity.User"%>
<%@page import="java.util.List"%>
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>问答系统后台</title>

<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">

<!-- layui css -->
<link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>

<body>

	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#navbar" aria-expanded="false"
				aria-controls="navbar">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="#">问答系统后台</a>
		</div>
		<div id="navbar" class="navbar-collapse collapse">
			<ul class="nav navbar-nav navbar-right">
				<li><a href="#">仪表盘</a></li>
				<li><a href="#">设置</a></li>
				<li><a href="#">帮助</a></li>
			</ul>
			<form class="navbar-form navbar-right" method="post"
				action="as.do?op=queryPage">
				<input type="text" class="form-control" id="key" value="${key }"
					name="key" placeholder="搜索...">
				<button class="btn btn-default" type="submit">搜索</button>
			</form>
		</div>
	</div>
	</nav>

	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="index.jsp">首页<span class="sr-only">(current)</span></a>
					</li>
					<li><a href="Userservlet?op=list">用户列表</a></li>
					<li><a href="addUsers.jsp">新增用户</a></li>
					<li><a href="#">Export</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li><a href="qs?op=querylist">问题列表</a></li>
					<li><a href="qs?op=add">提出问题</a></li>
					<li><a href="">One more nav</a></li>
					<li><a href="">Another nav item</a></li>
					<li><a href="">More navigation</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li class="active"><a href="as.do?op=query">答案管理</a></li>
					<li><a href="">One more nav</a></li>
					<li><a href="">Another nav item</a></li>
				</ul>
			</div>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
				<h2 class="sub-header">用户信息</h2>
				<div class="table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>问题标题</th>
								<th>提问用户</th>
								<th>提出时间</th>
								<th>回答内容</th>
								<th>回答时间</th>
								<th>回答用户</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						<c:if test="${pdata.data==null}">
							<% response.sendRedirect("as.do?op=query"); %>
						</c:if>
							<c:forEach items="${requestScope.list}" var="a">
								<tr>
									<td>${a.aid }</td>
									<td>${a.title }</td>
									<td>${a.qusername }</td>
									<td>${a.qdate }</td>
									<td>${a.acontent }</td>
									<td>${a.adate }</td>
									<td>${a.ausername }</td>
									<td class="col-md-2">
										<button class="btn btn-link btn-update">修改</button> <a
										class="btn btn-link" href="as.do?op=del&id=${a.aid }">删除</a>
									</td>
								</tr>
							</c:forEach>

						</tbody>
					</table>
				</div>
<!--
				<div class="row clearfix">
					<div class="col-md-12 column text-center">
						<ul class="pagination">
							<li><a href="javascript:prePage();">上一页</a></li>
							<c:forEach begin="1" end="${requestScope.pdata.totalPage}"
								var="index">
								<c:choose>
									<c:when test="${index== requestScope.pdata.page }">
										<li class="active"><a href="#">${index}</a></li>
									</c:when>
									<c:otherwise>
										<li><a href="javascript:jumpTo(${index});">${index}</a></li>
									</c:otherwise>
								</c:choose>
							</c:forEach>
							<li><a href="javascript:nextPage();">下一页</a></li>
						</ul>
					</div>  -->

					<!-- layui分页 -->
					<div style="text-align:center;" id="layuiPage"></div>
				</div>
			</div>
		</div>

	</div>

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="js/jquery-3.3.1.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script>
		$(function() {

			$(".btn-update")
					.click(
							function() {
								if ($(this).text() == "确定") {
									var userId = $(this).parents("tr").find(
											"input").eq(0).val();
									var userName = $(this).parents("tr").find(
											"input").eq(1).val();
									var userSex = $(this).parents("tr").find(
											"input").eq(2).val();
									var userTel = $(this).parents("tr").find(
											"input").eq(3).val();
									var userAddress = $(this).parents("tr")
											.find("input").eq(4).val();
									var userLevel = ($(this).parents("tr")
											.find("input").eq(5).val() == "管理员") ? 0
											: 1;
									var userState = ($(this).parents("tr")
											.find("input").eq(6).val() == "启用") ? 0
											: 1;
									$
											.ajax({
												type : "get",
												url : "Userservlet?op=update",
												contentType : 'application/json;charset=utf-8',
												data : {
													userId : userId,
													userName : userName,
													userSex : userSex,
													userTel : userTel,
													userAddress : userAddress,
													userLevel : userLevel,
													userState : userState
												},
												success : function(data) {
													location.href = "Userservlet?op=list";
												},
												error : function(data) {
													alert(data);
												}
											});
								}
								if ($(this).text() == "修改") {
									$(this).text("确定");
									$(this).parent().siblings("td").each(
											function() {
												$(this).html(
														"<input style='width:55px;' type='text' value='"
																+ $(this)
																		.text()
																+ "' />");
											});
								}

							});

		});
		
		function prePage(){
			var page=1;
			if(${pdata.page}>1){
				page=${pdata.page}-1;
			}
			location.href="as.do?op=queryPage&page="+page+"&key="+document.getElementById("key").value;
		}
		function nextPage(){
			var page=${pdata.page};
			if(page<${pdata.totalPage}){
				page=page+1;
			}
			location.href="as.do?op=queryPage&page="+page+"&key="+document.getElementById("key").value;
		}
		function jumpTo(page){
			location.href="as.do?op=queryPage&page="+page+"&key="+document.getElementById("key").value;
		}
	</script>

	<!-- layui js -->
	<script src="layui/layui.js" charset="utf-8"></script>
	<script>
layui.use(['laypage', 'layer'], function(){
  var laypage = layui.laypage
  ,layer = layui.layer;
  

  //完整功能
  laypage.render({
    elem: 'layuiPage'
    ,count: ${pdata.total}
  	,limit:${pdata.pageSize}
  	,limits:[1,2,3]
  	,curr:${pdata.page}
  	,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
    ,jump: function(obj,first){
     if(!first){
    	location.href="as.do?op=queryPage&pageSize="+obj.limit+"&page="+obj.curr+"&key="+document.getElementById("key").value;
     }
    }
  });

  
});
</script>
</body>

</html>